package jsu.xxy.coffee3.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jsu.xxy.coffee3.Utils.MD5;
import jsu.xxy.coffee3.domain.Comments;
import jsu.xxy.coffee3.domain.Order;
import jsu.xxy.coffee3.domain.Staffs;
import jsu.xxy.coffee3.domain.com_score;
import jsu.xxy.coffee3.mapper.CommentsMapper;
import jsu.xxy.coffee3.service.CommentsService;
import jsu.xxy.coffee3.service.impl.CommentsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/comments")
public class commentsController {
    @Autowired
    CommentsMapper commentsMapper;
    @Autowired
    CommentsServiceImpl commentsService;
    @RequestMapping("addComment")

    @Operation(summary = "添加评论，需要订单号orderid,评论内容comment，分数score，用户名userName")
    public boolean addComment(int orderid, String comment, double score , String userName)
    {
        return commentsService.addComment(orderid,comment,score,userName);

    }

    @RequestMapping("getAllComments")
    @Operation(summary = "全部评论信息")
    public com_score getAllComments()
    {
        return commentsService.getAllComments();

    }

    @GetMapping("getCommentsByGBK")
    @Operation(summary = "通过好评，差评，关键字")
    public Page<Comments> getCommentsByGBK(@RequestParam String com, @RequestParam (required = false)String key,
                                 @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                 @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
    {

        return commentsService.getCommentsByGBK(com,key,pageNo,pageSize);

    }

    @GetMapping("getAllCommentsPage")
    @Operation(summary = "分页全部评论信息")
    public Page<Comments> getAllCommentsPage(@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
    {
        return commentsService.getAllCommentsPage(pageNo,pageSize);

    }
}
